import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Req,
  Query,
  Res
} from '@nestjs/common';
import { PostService } from './post.service';
import { CreatePostDto } from './dto/create-post.dto';
import { UpdatePostDto } from './dto/update-post.dto';
import { QueryPostDto } from './dto/query-post.dto';
import { DeletePostDto } from './dto/delete-post.dto';
import { Request,Response } from 'express';
import {
  ApiTags,
  ApiOperation,
  ApiBearerAuth,
} from '@nestjs/swagger';
import { StatusChangeDto } from 'src/common/baseDto/status-change.dto';
import { RequirePermission } from 'src/decorator/reuqire-permission';

@ApiTags('岗位管理')
@ApiBearerAuth()
@Controller('post')
export class PostController {
  constructor(private readonly postService: PostService) {}

  @Post()
  @ApiOperation({summary:'创建岗位'})
  @RequirePermission("system:post:add")
  create(@Body() createPostDto: CreatePostDto,@Req() req:Request) {
    return this.postService.create(createPostDto,req);
  }

  @Get()
  @ApiOperation({summary:'获取岗位列表'})
  @RequirePermission("system:post:list")
  findAll(@Query() query:QueryPostDto) {
    return this.postService.findAll(query);
  }

  @Get(':id')
  @ApiOperation({summary:'获取岗位详情'})
  findOne(@Param('id') id: string) {
    return this.postService.findOne(+id);
  }

  @Patch(':id')
  @ApiOperation({summary:'更新岗位'})
  @RequirePermission("system:post:edit")
  update(@Param('id') id: string, @Body() updatePostDto: UpdatePostDto,@Req() req:Request) {
    return this.postService.update(+id, updatePostDto,req);
  }

  @Post('statusChange')
  @ApiOperation({ summary: '更新岗位状态' })
  @RequirePermission("system:post:edit")
  statusChange(@Body() statusChangeDto: StatusChangeDto,@Req() req:Request) {
    return this.postService.statusChange(statusChangeDto,req);
  }

  @Post('delete')
  @ApiOperation({summary:'删除岗位'})
  @RequirePermission("system:post:remove")
  remove(@Body() deletePostDto: DeletePostDto) {
    return this.postService.remove(deletePostDto);
  }

  @Post('excel')
  @ApiOperation({ summary: '导出岗位' })
  @RequirePermission("system:post:export")
  exportToExcel(@Res() res: Response) {
    return this.postService.exportToExcel(res);
  }
}
